<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="12">
            <a-form-item label="公司名称">
              <j-input placeholder="输入公司名称模糊查询" v-model="queryParam.companyName"></j-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-form-item label="认证状态">
              <j-dict-select-tag v-model="queryParam.authCheckStatus" placeholder="请选择认证状态" dictCode="auth_check_status"/>
            </a-form-item>
          </a-col>
          
          
          <a-col :md="6" :sm="8">
            <a-form-item label="手机号码">
              <a-input placeholder="请输入手机号码" v-model="queryParam.cphone"></a-input>
            </a-form-item>
          </a-col>
          
        <template v-if="toggleSearchStatus">

          <a-col :md="6" :sm="8">
            <a-form-item label="用户真实姓名">
              <a-input placeholder="请输入用户真实姓名" v-model="queryParam.realname"></a-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-form-item label="身份证号码">
              <a-input placeholder="请输入身份证号码" v-model="queryParam.idcardCode"></a-input>
            </a-form-item>
          </a-col>

          </template>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
      <a-button type="primary" icon="download" @click="handleExportXls('认证审核信息')">导出</a-button>
      <!-- <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->


      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay" @click="handleMenuClick">
          <a-menu-item key="3">
            <a-icon type="lock" @click="batchFrozen('3')"/>
            认证不通过
        </a-menu-item>

        <a-menu-item key="2">
            <a-icon type="unlock" @click="batchFrozen('2')"/>
            认证通过
       </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>



      
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        style="word-break:break-all"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">

          <a v-if="record.authCheckStatus==1">
                <a-popconfirm title="确定修改状态为《认证审核通过吗》？" @confirm="() => handleFrozenCheck(record.id,2)">
                  <a>审核通过</a>
                </a-popconfirm>
                <a-divider type="vertical"/>
                <a-popconfirm title="确定修改状态为《认证审核不通过吗》？" @confirm="() => handleFrozenCheck(record.id,3)">
                  <a>审核未通过</a>
                </a-popconfirm>
          </a>

          <span v-if="record.authCheckStatus==2">
               <font color='red'>审核通过</font>
          </span>
          <span v-if="record.authCheckStatus==3">
               <font color='red'>审核未通过</font>
          </span>

          <a-divider type="vertical"/>

         <!-- <a-menu-item> -->
                <a href="javascript:;" @click="handleDetail(record)">详情</a>
        <!-- </a-menu-item> -->
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <authInfo-modal ref="modalForm" @ok="modalFormOk"></authInfo-modal>
  </a-card>
</template>

<script>
  import AuthInfoModal from './modules/AuthInfoModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {frozenBatchCheckAuth} from '@/api/api'
  import {putAction} from '@/api/manage';
  import JInput from '@/components/jeecg/JInput'
  import JDictSelectTag from '@/components/dict/JDictSelectTag'

  export default {
    name: "AuthInfoList",
    mixins:[JeecgListMixin],
    components: {
      AuthInfoModal,
      JInput,
      JDictSelectTag
    },
    data () {
      return {
        description: '认证审核信息管理页面',
        // 表头
        columns: [
          // {
          //   title: '#',
          //   dataIndex: '',
          //   key:'rowIndex',
          //   width:60,
          //   align:"center",
          //   customRender:function (t,r,index) {
          //     return parseInt(index)+1;
          //   }
          //  },
		   {
            title: '认证用户id',
            align:"center",
            width:80,
            dataIndex: 'userid'
            
           },
		   {
            title: '真实姓名',
            align:"center",
            width:60,
            dataIndex: 'realname'
           },
		   {
            title: '身份证号码',
            align:"center",
            width:80,
            dataIndex: 'idcardCode'
           },
		  //  {
      //       title: '身份证反面',
      //       align:"center",
      //       dataIndex: 'idcardBehindImg'
      //      },
		  //  {
      //       title: '身份证正面',
      //       align:"center",
      //       dataIndex: 'idcardFrontImg'
      //      },
      {
            title: '企业名称',
            align:"center",
            width:100,
            dataIndex: 'companyName'
           },
		  //  {
      //       title: '企业营业执照',
      //       align:"center",
      //       dataIndex: 'businessLicenseImg'
      //      },
		   
		   {
            title: '用户职位',
            align:"center",
            width:60,
            dataIndex: 'userPosition'
           },
		   {
            title: '联系方式',
            align:"center",
            width:70,
            dataIndex: 'cphone'
           },
		  //  {
      //       title: '授权书',
      //       align:"center",
      //       dataIndex: 'authorization'
      //      },
		   {
            title: '认证状态',
            align: "center",
            width: 60,
            dataIndex: 'authCheckStatus_dictText',
          },
		   {
            title: '备注',
            align:"center",
            width:120,
            dataIndex: 'conment'
           },
           {
            title: '审核时间',
            align:"center",
            width:90,
            dataIndex: 'checkTime'
           },
		   {
            title: '创建时间',
            align:"center",
            width:90,
            dataIndex: 'createTime'
           },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            width:150,
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          list: "/authinfo/list",
          delete: "/authinfo/delete",
          deleteBatch: "/authinfo/deleteBatch",
          exportXlsUrl: "/authinfo/exportXls",
          importExcelUrl: "/authinfo/importExcel",
       },
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: {

      batchFrozen: function (authCheckStatus) {
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return false;
        } else {
          let ids = "";
          let that = this;
          
          
          
          that.selectedRowKeys.forEach(function (val) {
            ids += val + ",";
          });
          that.$confirm({
            title: "确认操作",
            content: "是否" + (authCheckStatus == 2 ? "认证通过" : "认证不通过") + "选中账号?",
            onOk: function () {
              frozenBatchCheckAuth({ids: ids, authCheckStatus: authCheckStatus}).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              });
            }
          });
        }
      },
      handleMenuClick(e) {
        if (e.key == 1) {
          this.batchDel();
        } else if (e.key == 2) {
          this.batchFrozen(2);
        } else if (e.key == 3) {
          this.batchFrozen(3);
        }
      },




      handleFrozenCheck: function (id, authCheckStatus) {
        let that = this;
        frozenBatchCheckAuth({ids: id, authCheckStatus: authCheckStatus}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
        });
      },
     
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>